package com.mastercard.labs

class CardService {
	
	/**
	 * This will return all cards belong to user
	 * @param user
	 * @return arraylist of cards
	 */
	def getCards(User user) {
		def userCards = UserCard.findAllByUser(user)
		ArrayList cards = new ArrayList()
		for (UserCard uCard in userCards) {
			def card = uCard.card
			if(!card.deleted)
				cards.add(card)
		}
		log.info "${user.username} " + cards.size()
		return cards
	}
	
	def getUser (Card card){
		def userCard = UserCard.findAllByCard(card)
		log.info "userCard $userCard"
		return userCard.get(0).user
	}
}
